﻿using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using cv2 = OpenCvSharp.Cv2;
namespace OpencvProjectBase.OpencvSharpTestForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = "./test.bmp";
            Mat src= cv2.ImRead(path);
            cv2.CvtColor(src, src, ColorConversionCodes.BGR2GRAY);
            Mat thres=new Mat();
            //cv2.ImShow("gray", src);
            cv2.Threshold(src, thres, 50, 255, ThresholdTypes.Binary);
            //cv2.ImShow("thres", thres);

            Mat con=new Mat();
            cv2.ConnectedComponents(src, con);
            con.ConvertTo(con, MatType.CV_8UC1);
            cv2.ImShow("connected", con);

            cv2.WaitKey(1);
        }
    }
}
